/**
 * Alipay.com Inc.
 * Copyright (c) 2004-2012 All Rights Reserved.
 */
package com.losenote.service.result;

import java.util.HashMap;
import java.util.Map;

import com.losenote.enums.LnResultCodeEnum;
import com.losenote.model.ToString;

/**
 * 精确服务返回结果基类
 * 
 * @author jingyu.dan
 * @version $Id: AcResult.java, v 0.1 2012-11-7 下午8:18:26 jingyu.dan Exp $
 */
public class LnResult extends ToString {

    /** serialVersionUID */
    private static final long     serialVersionUID = 4887277624451526447L;

    /** 成功标识 */
    protected boolean             success          = false;

    /** 结果码 */
    protected String              code             = "UNKNOWN";

    /** 返回信息 */
    protected String              message          = "默认信息";

    /** 附加参数 */
    protected Map<String, Object> relatedAttr      = new HashMap<String, Object>();

    /**
     * 默认构造函数
     */
    public LnResult() {

    }

    /**
     * 带结果码和结果信息的构造函数
     * 
     * @param
     *       <li>"SUCCESS", "操作成功"
     *       <li>"SYSTEM_FAILURE", "系统错误"
     *       <li>"NULL_ARGUMENT", "参数为空"
     *       <li>"ILLEGAL_ARGUMENT", "参数不正确"
     *       <li>"LOGIC_ERROR", "逻辑错误"
     *       <li>"DEPEND_FAILURE", "依赖外部接口失败"
     *       <li>"INEXISTENCE_CONFIG", "配置不存在"
     */
    public LnResult(String code, String message) {

        this.code = code;
        this.message = message;
    }

    /**
     * 含操作结果的构造函数
     * 
     * @param success 成功标志
     */
    public LnResult(boolean success) {
        this.success = success;
        if (success) {
            this.code = LnResultCodeEnum.SUCCESS.getCode();
            this.message = LnResultCodeEnum.SUCCESS.getDescription();
        }
    }

    /**
     * 构造方法
     * @param success       成功标示
     * @param resultCode    返回值code
     */
    public LnResult(boolean success, LnResultCodeEnum resultCode) {
        this.success = success;
        this.code = resultCode.getCode();
        this.message = resultCode.getDescription();
    }

    /**
     * 返回默认成功对象
     * 
     * @return
     */
    public static LnResult retSuccess() {

        return new LnResult(true, LnResultCodeEnum.SUCCESS);
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Map<String, Object> getRelatedAttr() {
        return relatedAttr;
    }

    public void setRelatedAttr(Map<String, Object> relatedAttr) {
        this.relatedAttr = relatedAttr;
    }

}
